﻿using System.Collections.Generic;
using XLua;
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif

namespace XLua.CSObjectWrap
{
    using Utils = XLua.Utils;

    public class UnityEngineObjectWrap
    {
        public static void __Register(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
            System.Type type = typeof(UnityEngine.Object);
            Utils.BeginObjectRegister(type, L, translator, 1, 4, 2, 2);
            Utils.RegisterFunc(L, Utils.OBJ_META_IDX, "__eq", __EqMeta);

            Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetInstanceID", _m_GetInstanceID);
            Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetHashCode", _m_GetHashCode);
            Utils.RegisterFunc(L, Utils.METHOD_IDX, "Equals", _m_Equals);
            Utils.RegisterFunc(L, Utils.METHOD_IDX, "ToString", _m_ToString);

            Utils.RegisterFunc(L, Utils.GETTER_IDX, "name", _g_get_name);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "hideFlags", _g_get_hideFlags);

            Utils.RegisterFunc(L, Utils.SETTER_IDX, "name", _s_set_name);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "hideFlags", _s_set_hideFlags);

            Utils.EndObjectRegister(type, L, translator, null, null, null, null, null);

            Utils.BeginClassRegister(type, L, __CreateInstance, 7, 0, 0);
            Utils.RegisterFunc(L, Utils.CLS_IDX, "Instantiate", _m_Instantiate_xlua_st_);
            Utils.RegisterFunc(L, Utils.CLS_IDX, "Destroy", _m_Destroy_xlua_st_);
            Utils.RegisterFunc(L, Utils.CLS_IDX, "DestroyImmediate", _m_DestroyImmediate_xlua_st_);
            Utils.RegisterFunc(
                L,
                Utils.CLS_IDX,
                "FindObjectsOfType",
                _m_FindObjectsOfType_xlua_st_
            );
            Utils.RegisterFunc(
                L,
                Utils.CLS_IDX,
                "DontDestroyOnLoad",
                _m_DontDestroyOnLoad_xlua_st_
            );
            Utils.RegisterFunc(L, Utils.CLS_IDX, "FindObjectOfType", _m_FindObjectOfType_xlua_st_);

            Utils.EndClassRegister(type, L, translator);
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int __CreateInstance(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    var gen_ret = new UnityEngine.Object();
                    translator.Push(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Object constructor!");
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int __EqMeta(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                if (
                    translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Object>(L, 2)
                )
                {
                    UnityEngine.Object leftside = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Object rightside = (UnityEngine.Object)
                        translator.GetObject(L, 2, typeof(UnityEngine.Object));

                    LuaAPI.lua_pushboolean(L, leftside == rightside);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return LuaAPI.luaL_error(
                L,
                "invalid arguments to right hand of == operator, need UnityEngine.Object!"
            );
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_GetInstanceID(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);

                {
                    var gen_ret = gen_to_be_invoked.GetInstanceID();
                    LuaAPI.xlua_pushinteger(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_GetHashCode(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);

                {
                    var gen_ret = gen_to_be_invoked.GetHashCode();
                    LuaAPI.xlua_pushinteger(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_Equals(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);

                {
                    object _other = translator.GetObject(L, 2, typeof(object));

                    var gen_ret = gen_to_be_invoked.Equals(_other);
                    LuaAPI.lua_pushboolean(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_Instantiate_xlua_st_(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && translator.Assignable<UnityEngine.Object>(L, 1))
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));

                    var gen_ret = UnityEngine.Object.Instantiate(_original);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (gen_param_count == 1 && translator.Assignable<UnityEngine.Object>(L, 1))
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));

                    var gen_ret = UnityEngine.Object.Instantiate(_original);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 2
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Transform>(L, 2)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Transform _parent = (UnityEngine.Transform)
                        translator.GetObject(L, 2, typeof(UnityEngine.Transform));

                    var gen_ret = UnityEngine.Object.Instantiate(_original, _parent);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 2
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Transform>(L, 2)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Transform _parent = (UnityEngine.Transform)
                        translator.GetObject(L, 2, typeof(UnityEngine.Transform));

                    var gen_ret = UnityEngine.Object.Instantiate(_original, _parent);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 3
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Transform>(L, 2)
                    && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 3)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Transform _parent = (UnityEngine.Transform)
                        translator.GetObject(L, 2, typeof(UnityEngine.Transform));
                    bool _instantiateInWorldSpace = LuaAPI.lua_toboolean(L, 3);

                    var gen_ret = UnityEngine.Object.Instantiate(
                        _original,
                        _parent,
                        _instantiateInWorldSpace
                    );
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 3
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Transform>(L, 2)
                    && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 3)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Transform _parent = (UnityEngine.Transform)
                        translator.GetObject(L, 2, typeof(UnityEngine.Transform));
                    bool _worldPositionStays = LuaAPI.lua_toboolean(L, 3);

                    var gen_ret = UnityEngine.Object.Instantiate(
                        _original,
                        _parent,
                        _worldPositionStays
                    );
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 3
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Vector3>(L, 2)
                    && translator.Assignable<UnityEngine.Quaternion>(L, 3)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Vector3 _position;
                    translator.Get(L, 2, out _position);
                    UnityEngine.Quaternion _rotation;
                    translator.Get(L, 3, out _rotation);

                    var gen_ret = UnityEngine.Object.Instantiate(_original, _position, _rotation);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 3
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Vector3>(L, 2)
                    && translator.Assignable<UnityEngine.Quaternion>(L, 3)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Vector3 _position;
                    translator.Get(L, 2, out _position);
                    UnityEngine.Quaternion _rotation;
                    translator.Get(L, 3, out _rotation);

                    var gen_ret = UnityEngine.Object.Instantiate(_original, _position, _rotation);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 4
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Vector3>(L, 2)
                    && translator.Assignable<UnityEngine.Quaternion>(L, 3)
                    && translator.Assignable<UnityEngine.Transform>(L, 4)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Vector3 _position;
                    translator.Get(L, 2, out _position);
                    UnityEngine.Quaternion _rotation;
                    translator.Get(L, 3, out _rotation);
                    UnityEngine.Transform _parent = (UnityEngine.Transform)
                        translator.GetObject(L, 4, typeof(UnityEngine.Transform));

                    var gen_ret = UnityEngine.Object.Instantiate(
                        _original,
                        _position,
                        _rotation,
                        _parent
                    );
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 4
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && translator.Assignable<UnityEngine.Vector3>(L, 2)
                    && translator.Assignable<UnityEngine.Quaternion>(L, 3)
                    && translator.Assignable<UnityEngine.Transform>(L, 4)
                )
                {
                    UnityEngine.Object _original = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    UnityEngine.Vector3 _position;
                    translator.Get(L, 2, out _position);
                    UnityEngine.Quaternion _rotation;
                    translator.Get(L, 3, out _rotation);
                    UnityEngine.Transform _parent = (UnityEngine.Transform)
                        translator.GetObject(L, 4, typeof(UnityEngine.Transform));

                    var gen_ret = UnityEngine.Object.Instantiate(
                        _original,
                        _position,
                        _rotation,
                        _parent
                    );
                    translator.Push(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }

            return LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Object.Instantiate!");
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_Destroy_xlua_st_(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && translator.Assignable<UnityEngine.Object>(L, 1))
                {
                    UnityEngine.Object _obj = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));

                    UnityEngine.Object.Destroy(_obj);

                    return 0;
                }
                if (
                    gen_param_count == 2
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2)
                )
                {
                    UnityEngine.Object _obj = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    float _t = (float)LuaAPI.lua_tonumber(L, 2);

                    UnityEngine.Object.Destroy(_obj, _t);

                    return 0;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }

            return LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Object.Destroy!");
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_DestroyImmediate_xlua_st_(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && translator.Assignable<UnityEngine.Object>(L, 1))
                {
                    UnityEngine.Object _obj = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));

                    UnityEngine.Object.DestroyImmediate(_obj);

                    return 0;
                }
                if (
                    gen_param_count == 2
                    && translator.Assignable<UnityEngine.Object>(L, 1)
                    && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2)
                )
                {
                    UnityEngine.Object _obj = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));
                    bool _allowDestroyingAssets = LuaAPI.lua_toboolean(L, 2);

                    UnityEngine.Object.DestroyImmediate(_obj, _allowDestroyingAssets);

                    return 0;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }

            return LuaAPI.luaL_error(
                L,
                "invalid arguments to UnityEngine.Object.DestroyImmediate!"
            );
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_FindObjectsOfType_xlua_st_(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && translator.Assignable<System.Type>(L, 1))
                {
                    System.Type _type = (System.Type)
                        translator.GetObject(L, 1, typeof(System.Type));

                    var gen_ret = UnityEngine.Object.FindObjectsOfType(_type);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 2
                    && translator.Assignable<System.Type>(L, 1)
                    && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2)
                )
                {
                    System.Type _type = (System.Type)
                        translator.GetObject(L, 1, typeof(System.Type));
                    bool _includeInactive = LuaAPI.lua_toboolean(L, 2);

                    var gen_ret = UnityEngine.Object.FindObjectsOfType(_type, _includeInactive);
                    translator.Push(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }

            return LuaAPI.luaL_error(
                L,
                "invalid arguments to UnityEngine.Object.FindObjectsOfType!"
            );
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_DontDestroyOnLoad_xlua_st_(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                {
                    UnityEngine.Object _target = (UnityEngine.Object)
                        translator.GetObject(L, 1, typeof(UnityEngine.Object));

                    UnityEngine.Object.DontDestroyOnLoad(_target);

                    return 0;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_FindObjectOfType_xlua_st_(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && translator.Assignable<System.Type>(L, 1))
                {
                    System.Type _type = (System.Type)
                        translator.GetObject(L, 1, typeof(System.Type));

                    var gen_ret = UnityEngine.Object.FindObjectOfType(_type);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    gen_param_count == 2
                    && translator.Assignable<System.Type>(L, 1)
                    && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2)
                )
                {
                    System.Type _type = (System.Type)
                        translator.GetObject(L, 1, typeof(System.Type));
                    bool _includeInactive = LuaAPI.lua_toboolean(L, 2);

                    var gen_ret = UnityEngine.Object.FindObjectOfType(_type, _includeInactive);
                    translator.Push(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }

            return LuaAPI.luaL_error(
                L,
                "invalid arguments to UnityEngine.Object.FindObjectOfType!"
            );
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_ToString(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);

                {
                    var gen_ret = gen_to_be_invoked.ToString();
                    LuaAPI.lua_pushstring(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_name(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);
                LuaAPI.lua_pushstring(L, gen_to_be_invoked.name);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_hideFlags(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);
                translator.Push(L, gen_to_be_invoked.hideFlags);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_name(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.name = LuaAPI.lua_tostring(L, 2);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_hideFlags(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Object gen_to_be_invoked = (UnityEngine.Object)
                    translator.FastGetCSObj(L, 1);
                UnityEngine.HideFlags gen_value;
                translator.Get(L, 2, out gen_value);
                gen_to_be_invoked.hideFlags = gen_value;
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }
    }
}
